package top.tresman.cxxcommon.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import top.tresman.cxxcommon.annotation.ChkMobile;

import java.util.regex.Pattern;

public class MobileValidator implements ConstraintValidator<ChkMobile, String> {
    // 中国大陆手机号正则（11位，1开头，第二位为3-9）
    private static final Pattern MOBILE_PATTERN =
            Pattern.compile("^1[3-9]\\d{9}$");

    @Override
    public boolean isValid(String mobile, ConstraintValidatorContext context) {
        if (mobile == null || mobile.isBlank()) {
            return false; // 根据需求调整空值处理
        }
        return MOBILE_PATTERN.matcher(mobile).matches();
    }
}
